package com.cos.openapi.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @author: COS
 * @time: 2021/11/23 16:28
 * @description: 统一返回数据类型
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ResponseResult<T> {
    private boolean status;
    private String msg;
    private T t;

    /**
     * @author: COS
     * @return:
     * @time: 2021/11/23 16:31
     * @description: 成功响应的信息
     */
    public static ResponseResult getSuccess() {
        return new ResponseResult(ResponseCode.SUCCESS.getStatus(), ResponseCode.SUCCESS.getCommon(), null);
    }

    public static ResponseResult getSuccess(String msg) {
        return new ResponseResult(true, msg, null);
    }

    public static <T> ResponseResult getSuccess(T t) {
        return new ResponseResult(true, null, t);
    }

    public static <T> ResponseResult getSuccess(String msg, T t) {
        return new ResponseResult(true, msg, t);
    }

    /**
     * @author: COS
     * @return:
     * @time: 2021/11/23 16:32
     * @description: 失败响应
     */
    public static ResponseResult getFail() {
        return new ResponseResult(false, null, null);
    }

    public static ResponseResult getFail(String msg) {
        return new ResponseResult(false, msg, null);
    }

    public static <T> ResponseResult getFail(T t) {
        return new ResponseResult(false, null, t);
    }

    public static <T> ResponseResult getFail(String msg, T t) {
        return new ResponseResult(false, msg, t);
    }
}
